home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8414 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: const's and Borland C++
  5. Date: 17 Feb 1996 23:05:34 GMT
  6. Organization: Borland International
  7. Distribution: world
  8. Message-ID: <4g5mvu$m25@druid.borland.com>
  9. References: <4g2gu8$hpe@enst.enst.fr>
  10. NNTP-Posting-Host: pbecker.borland.com
  11. Mime-Version: 1.0
  12. Content-Type: Text/Plain; charset=ISO-8859-1
  13. X-Newsreader: WinVN 0.99.5
  14.  
  15. In article <4g2gu8$hpe@enst.enst.fr>, orfanos@ima.enst.fr says...
  16. >
  17. >
  18. >Hello,
  19. >
  20. >What's going here on with float const's and Borland C++ 4.5?
  21. >
  22. >        --- MAGWEG.H ---
  23. >        const float FOO1 = 23.0;
  24. >        const float FOO2 = -62.33;
  25. >
  26. >        --- MAGWEG.CPP ---
  27. >        #include "magweg.h"
  28. >        
  29. >        int main()
  30. >        {
  31. >                float f = FOO1;
  32. >                f /= 2;
  33. >        
  34. >           return 0;
  35. >        }
  36. >
  37. >        --- compiler messages ---
  38. >        Compiling MAGWEG.CPP:
  39. >        Warning MAGWEG.H 1: Cannot create pre-compiled header:
  40. >                                      initialized data in header
  41. >        Warning MAGWEG.CPP 11: 'FOO2' is declared but never used
  42. >        Linking magweg.exe:
  43. >
  44. >The first warning should not be emitted, because I disabled
  45. >it in Options|Project|Messages|General.
  46.  
  47.  
  48. >The second warning should never be emitted.
  49.  
  50. Why not? You defined a data object and did not use it, as the warning said. 
  51. Note that a const declaration is not like a #define. It says "I want a data 
  52. object of this type", so the compiler created one.
  53.  
  54. > In fact, it appears
  55. >only with float const's, not with int const's!
  56.  
  57. Yup. The compiler usually doesn't generate any storage for definitions of 
  58. const integral types, because it can put them in registers. Can't do that with 
  59. floating point types, so there has to be an object somewhere.
  60.     -- Pete
  61.  
  62.